#include<bits/stdc++.h>
using namespace std;
int n,m;
struct CAR{
    int d,v,a;
    double los,ros;//[los,ros)
    bool checked;
    vector<int>lcheck;
};
bool vecfind(vector<int> a,int b){
    for(int i=0;i<a.size();i++){
        if(a[i]==b)return true;
    }
    return false;
}
int dfs_delete(CAR c[],vector<int> deled,int num){
    for(int i=0;i<n;i++){
        int cnt=0;
        for(int j=0;j<c[i].lcheck.size();j++){
            if(vecfind(deled,c[i].lcheck[j]))cnt++;
        }
        if(cnt==c[i].lcheck.size()&&cnt!=0)return 0;
    }
    int maxdel=num;
    for(int i=0;i<m;i++){
        if(vecfind(deled,i))continue;
        deled.push_back(i);
        maxdel=max(maxdel,dfs_delete(c,deled,num+1));
        deled.pop_back();
    }
    return maxdel;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        int L,V;
        scanf("%d%d%d%d",&n,&m,&L,&V);
        CAR c[100001];
        int spt[100001];
        for(int i=0;i<n;i++){
                c[i].checked=0;
                scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);
                c[i].los=-1;
                c[i].ros=-1;
                if(c[i].a==0&&c[i].v>V)c[i].los=c[i].d,c[i].ros=L+1;
                else if(c[i].a<0&&c[i].v>V){
                    c[i].los=c[i].d;
                    c[i].ros=(V-c[i].v)/c[i].a+c[i].los;
                }else if(c[i].a>0){
                    if(c[i].v>V){
                        c[i].los=c[i].d;
                    }else c[i].los=(V-c[i].v)/c[i].a;
                    if(c[i].los<=L)c[i].ros=L+1;
                }
        }
        int cnt=0;
        for(int i=0;i<m;i++){
            scanf("%d",spt+i);
            for(int j=0;j<n;j++){
                if(spt[i]>=c[j].los&&spt[i]<c[j].ros){
                    if(!c[j].checked)cnt++;
                    c[j].checked=true;
                    c[j].lcheck.push_back(i);
                }
            }
        }
        printf("%d ",cnt);
        vector<int>tmp;
        printf("%d\n",dfs_delete(c,tmp,0));
    }
    return 0;
}
